﻿using BLL;
using BLL.Base;
using BLL.Basis;
using BLL.sys;
using Entity;
using Entity.SysEntity.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SysFrameWork;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tools;
using WebProject.Controllers.Base;

namespace WebProject.Controllers
{
    public class BasisController : BaseController
    {
        BaseDataBLL baseBLL;
        WareHouseBLL wareBLL;
       SysFrameWork.SystemBLL sysBLL;
        ProductInfoBLL proBLL;
        UserBLL userBLL;
     
        public BasisController()
        {

            baseBLL = new BaseDataBLL();
            wareBLL = new WareHouseBLL();
            sysBLL = new SysFrameWork.SystemBLL();
            proBLL = new ProductInfoBLL();
            userBLL = new UserBLL();
      
        }
        #region 视图

        //生产岗位配置
        public ActionResult PositionInfo()
        {
            return View();
        }
        //仓库列表
        public ActionResult HouseList()
        {
            return View();
        }
        //存货列表
        public ActionResult InventoryInfo()
        {
            return View();
        }
        //更新存货列表
        public ActionResult UpdateInventoryInfo()
        {
            return View();
        }
        public ActionResult UpdatePosition()
        {
            return View();
        }
        /// <summary>
        /// 仓库货位
        /// </summary>
        /// <returns></returns>
        public ActionResult WarePosition()
        {
            return View();
        }
        //更新仓库货位
        public ActionResult UpdateWarePosition()
        {
            return View();
        }

        public ActionResult BanGunDetail()
        {
            return View();
        }
     
        public ActionResult UserPosition()
        {
            return View();
        }
        public ActionResult UserGongXu()
        {
            return View();
        }
        public ActionResult UpdateUserPosition()
        {
            return View();
        }


        //其他绩效基础数据
        public ActionResult YangBanStatus()
        {
            return View();
        }

        //维修价格查询
        public ActionResult CommonDataInfo()
        {
            return View();
        }
        public ActionResult CommonDataUpdate()
        {

            return View();
        }

        //仓库信息
        public ActionResult WareHouseInfo()
        {
            return View();
        }
        //更新仓库信息
        public ActionResult UpdateWareHouseInfo()
        {
            return View();
        }

        //存货类别列表
        public ActionResult InventoryClass()
        {
            return View();
        }
        //更新存货大类
        public ActionResult UpdateInventoryClass()
        {
            return View();
        }


        public ActionResult UpdateOther()
        {
            return View();
        }

        public ActionResult PieceRate()
        {
            return View();
        }
        public ActionResult AddRate()
        {
            return View();
        }
   
        //客商信息
        public ActionResult CustomerInfo()
        {
            return View();
        }
        //更新客商信息
        public ActionResult UpdateCustomerInfo()
        {
            return View();
        }
        //版辊
        public ActionResult UpdateBanGun()
        {
            return View();
        }
        public ActionResult YangBanDetail()
        {
            return View();
        }
        public ActionResult UpdateTemplate()
        {
            return View();
        }

        public ActionResult PaiGongDistribution()
        {
            return View();
        }
        
        public ActionResult deptList()
        {
            return View();
        }
        #endregion

        [HttpPost]
        public JsonResult DelCommonData(string dataId)
        {
            return Json(baseBLL.DelCommonData(dataId));
        }

        [HttpPost]
        public JsonResult getCommonDataType(string type)
        {
            return Json(baseBLL.getCommonDataType(type));
        }
        [HttpPost]
        public JsonResult getCommonDataTop()
        {
            return Json(baseBLL.getCommonDataTop());
        }
        public JsonResult getParentCodes(string type)
        {
            return Json(baseBLL.getParentCodes());
        }

        [HttpPost]
        public JsonResult getDictionaryInfo(string type)
        {
            return Json(sysBLL.getDictionaryInfo(type, ""));//
        }
        [HttpPost]
        public JsonResult getCommonDataById(string dataId)
        {
            return Json(baseBLL.getCommonDataById(dataId));
        }
        [HttpPost]
        public JsonResult UpdateCommonData(string datas)
        {
            return Json(baseBLL.UpdateCommonData(datas));
        }
          [HttpPost]
        public JsonResult EditCommonNames(string dataId,string names)
        {
            return Json(baseBLL.EditCommonNames(dataId,names));
        }

        /// <summary>
        /// 数据同步统一接口
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult SyncData(string dataType)
        {
            ReturnResult rsl = new ReturnResult();
            if (dataType == "user")
            {
               // rsl = sysBLL.SyncUserData();
            }
            else if (dataType == "ven")
            {
                ProductInfoBLL venBLL = new ProductInfoBLL();
                rsl = venBLL.SyncInventory(false);
            }
            else if (dataType == "venClass")
            {
                ProductInfoBLL venBLL = new ProductInfoBLL();
                rsl = venBLL.SyncInventory(false,true);
            }
            else if (dataType == "wareHouse")
            {
                WareHouseBLL wareBLL = new WareHouseBLL();
                rsl = wareBLL.SyncWareHouse();
            }
            else if (dataType == "cu-Cu")
            {
                CustomBLL cuBLL = new CustomBLL();
                rsl = cuBLL.SyncCustom("Cu",false);
            }
            //else if (dataType == "cu-Sp")
            //{
            //    CustomBLL cuBLL = new CustomBLL();
            //    rsl = cuBLL.SyncCustom("Sp",false);
            //}
            else if (dataType == "dept")
            {
                CustomBLL cuBLL = new CustomBLL();
                rsl = userBLL.SyncDept( false);
            }
            return Json(rsl);
        }


        [HttpPost]
        public JsonResult GetInventoryByCode(string proCode)
        {
            return Json(proBLL.GetInventoryByCode(proCode));
        }
         [HttpPost]
        public JsonResult GetWareHousePosition(string wareCode)
        {
            WareHouseBLL wareBLL = new WareHouseBLL();
            return Json(wareBLL.GetWareHousePosition(wareCode));
        }
        

        /// <summary>
        /// 获取数据列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="cCode"></param>
        /// <param name="cName"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetDataList(string page, string limit, string condition, string dataType, string typesCode)
        {
            InventoryBLL ven = new InventoryBLL();
            string pageCount = "1";
            string msg = "";
            var datas = new object();
            var rsl = new ReturnResult();
            if (dataType == "cdb")
            {
               // rsl = sysBLL.CustomBaseInfo();
            }
            else if (dataType == "ven")
            {
                rsl = proBLL.InventoryList(page, limit, typesCode, ref pageCount, condition);//存货
            }
            else if (dataType == "venClass")
            {
                rsl = proBLL.InventoryClassList(page, limit, ref pageCount, condition);//存货大类
            }
            else if (dataType == "wareHouse")
            {
                WareHouseBLL wareBLL = new WareHouseBLL();
                rsl = wareBLL.getWareHouseList(page, limit, ref pageCount, condition);
            }
            else if (dataType == "selwh")
            {
                rsl = baseBLL.getWareHouseList(condition);
            } 
            //else if (dataType == "selps")
            //{
            //    rsl = baseBLL.getPostionList(condition, typesCode);
            //}
            //else if (dataType == "selcol" || dataType == "selbr")
            //{
            //    rsl = baseBLL.getInvproList(condition, dataType);
            //}
            //else if (dataType == "rate")
            //{
            //    PieceRateBLL rateBLL = new PieceRateBLL();
            //    rsl = rateBLL.getPieceRateList(page, limit, condition, ref pageCount);
            //}
            else if (dataType == "user")
            {
                rsl = baseBLL.getUserList(page, limit, ref pageCount, condition);
            }
            else if (dataType == "dept")
            {
                rsl = baseBLL.getDeptList(page, limit, ref pageCount, condition);
            }
            else if (dataType == "wp")
            {
                WareHouseBLL wareBLL = new WareHouseBLL();
                rsl = wareBLL.WarePositionList(condition);
            }
            else if (dataType == "cmdi")
            {
                rsl = baseBLL.getCommonDataInfo(condition);
            }
            else if (dataType.ToLower() == "cu" || dataType.ToLower() == "sp")
            {
                CustomBLL cuBLL = new CustomBLL();
                rsl = cuBLL.getCustomDataList(page, limit, ref pageCount, condition);
            }
            else if (dataType == "cmd")
            {
                rsl = baseBLL.getCommonDataList(page, limit, ref pageCount, condition);
            }
            //else if (dataType == "tList")
            //{
            //    rsl = baseBLL.TempPositionList(condition);
            //}
            //else if (dataType == "usp")
            //{
            //    rsl = baseBLL.getUserPositionList(page, limit, ref pageCount, condition);
            //}
           
            //else if (dataType == "ybr")
            //{
            //    ApproveRecordBLL appBLL = new ApproveRecordBLL();
            //    rsl = appBLL.BanGunRecords(condition, "YB");
            //}
           
            //else if (dataType == "pstlist")
            //{
            //    rsl = baseBLL.getPositionInfo(condition);
            //}
            //else if (dataType == "pgx")
            //{
            //    rsl = baseBLL.getUserGongXu(condition);
            //}
            //else if (dataType == "wap")//wareCode and positionCode
            //{
            //    //获取仓库和货位信息
            //    rsl= baseBLL.getWarePositions(page, limit, ref pageCount, condition);
            //}
          

            if (rsl.Result)
            {
                datas = rsl.Data;
            }
            else
            {
                msg = rsl.Message;
            }
            JsonResult js = new JsonResult();
            return new JsonResult()
            {
                Data = new
                {
                    count = pageCount,
                    msg = msg,
                    code = "0",
                    data = datas
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        [HttpPost]
        public JsonResult UpdateInventoryClass(string data)
        {
            return Json(baseBLL.UpdateInventoryClass(data));
        }

        [HttpPost]
        public JsonResult getInventoryClassById(string dataId)
        {
            return Json(baseBLL.getInventoryClassById(dataId));

        }

        //[HttpPost]
        //public JsonResult getInvproList(string type,string proCode)
        //{
        //    return Json(baseBLL.getInvproList(type,proCode));

        //}

        [HttpPost]
        public JsonResult DelInventoryClass(int dataId)
        {
            return Json(baseBLL.DelInventoryClass(dataId));
        }

        [HttpPost]
        public JsonResult UpdateWareHouseInfo(string data)
        {
            return Json(baseBLL.UpdateWareHouseInfo(data));
        }

        [HttpPost]
        public JsonResult getWareHouseInfoById(string dataId)
        {
            return Json(baseBLL.getWareHouseInfoById(dataId));
        }

        [HttpPost]
        public JsonResult DelWareHouseInfo(int dataId)
        {
            return Json(baseBLL.DelWareHouseInfo(dataId));
        }

        [HttpPost]
        public JsonResult UpdateWarePosition(string data)
        {
            return Json(baseBLL.UpdateWarePosition(data));
        }

        //[HttpPost]
        //public JsonResult getWarePositionById(string dataId)
        //{
        //    return Json(baseBLL.getWarePositionById(dataId));
        //}

        //[HttpPost]
        //public JsonResult DelWarePosition(int dataId)
        //{
        //    return Json(baseBLL.DelWarePosition(dataId));
        //}

        [HttpPost]
        public JsonResult UpdateInventoryInfo(string data)
        {
            return Json(baseBLL.UpdateInventoryInfo(data));
        }

        [HttpPost]
        public JsonResult getInventoryInfoById(string dataId)
        {
            return Json(baseBLL.getInventoryInfoById(dataId));
        }

        [HttpPost]
        public JsonResult DelInventoryInfo(int dataId)
        {
            return Json(baseBLL.DelInventoryInfo(dataId));
        }

        [HttpPost]
        public JsonResult UpdateCustomerInfo(string data)
        {
            return Json(baseBLL.UpdateCustomerInfo(data));
        }

 

        [HttpPost]
        public JsonResult venClassNavigation()
        {
            return Json(proBLL.venClassNavigation());
        }
        [HttpPost]
        public JsonResult CuClassNavigation(string dataType)
        {
            CustomBLL cuBLL = new CustomBLL();
            return Json(cuBLL.TreeClassNavigation(dataType));
        }
        [HttpPost]
        public JsonResult saveRateData(string datas)
        {
            PieceRateBLL rateBLL = new PieceRateBLL();
            return Json(rateBLL.saveRateData(datas));
        }
   
        [HttpPost]
        public JsonResult saveRepairPrice(string datas)
        {
            var repairPrice_BLL = new bl_RepairPrice();
            return Json(repairPrice_BLL.saveRepairPrice(datas));
        }

  

        [HttpPost]
        public JsonResult DelRepairPrice(string dataId)
        {
            var repairPrice_BLL = new bl_RepairPrice();
            return Json(repairPrice_BLL.DelRepairPrice(dataId));
        }
        [HttpPost]
        public JsonResult UpdateWageStandard(string datas)
        {
            return Json(baseBLL.UpdateWageStandard(datas));
        }
        [HttpPost]
        public JsonResult getStandardById(string dataId)
        {
            return Json(baseBLL.getStandardById(dataId));
        }
        [HttpPost]
        public JsonResult DelStandardById(string dataId)
        {
            return Json(baseBLL.DelStandardById(dataId));
        }
        [HttpPost]
        public JsonResult DelPositionByCode(string dataId, string pCode, string gwCode)
        {
            PieceRateBLL rateBLL = new PieceRateBLL();
            return Json(baseBLL.DelPositionByCode(pCode, gwCode, dataId));
        }

        [HttpPost]
        public JsonResult GetCommonData(string type)
        {
            return Json(baseBLL.GetCommonData(type));
        }
        [HttpPost]
        public JsonResult AddProductPosition(string datas, string tempCode, string gwName)
        {
            return Json(baseBLL.AddProductPosition(tempCode, datas, gwName));
        }

        [HttpPost]
        public JsonResult DelPositionInfo(string dataId)
        {
            return Json(baseBLL.DelPositionInfo(dataId));
        }
        [HttpPost]
        public JsonResult SetUserPosition(string datas)
        {
            return Json(baseBLL.SetUserPosition(datas));
        }

        [HttpPost]
        public JsonResult ShouFaInfo()
        {
            return Json(baseBLL.ShouFaInfo());
        }
        [HttpPost]
        public JsonResult SaveUserPosition(string datas)
        {
            return Json(baseBLL.SaveUserPosition(datas));
        }
        [HttpPost]
        public JsonResult DelUserPosition(string dataId)
        {
            return Json(baseBLL.DelUserPosition(dataId));
        }
        [HttpPost]
        public JsonResult GetSpecialAttribute(string proCode)
        {
            ProductInfoBLL proBLL = new ProductInfoBLL();
            return Json(proBLL.GetSpecialAttribute(proCode));
        }
     
        [HttpPost]
        public JsonResult SaveProductPosition(string tempCode, string gxCode)
        {
            return Json(baseBLL.SaveProductPosition(tempCode, gxCode));
        }
        [HttpPost]
        public JsonResult getPositonByCode(string tempCode)
        {
            return Json(baseBLL.getPositonByCode(tempCode));
        }
          [HttpPost]
        public JsonResult BarTypes()
        {
            return Json(baseBLL.barTypes());
        }
          [HttpPost]
          public JsonResult GetWareHouse()
          {
              return Json(wareBLL.WareHouseInfo());
          }
    
        
          [HttpPost]
          public JsonResult getUserGongXu(string userCode)
          {
              return Json(baseBLL.getUserGongXu(userCode));
          }
             [HttpPost]
          public JsonResult SaveUserGongXu(string userCode, string gxCodes)
          {
              return Json(baseBLL.SaveUserGongXu(userCode,gxCodes));
          }



    }


}